<?php

/**
 * Created by PhpStorm.
 * User: hanbin
 * Date: 17/3/30
 * Time: 上午10:22
 */
$env_hosts = [
    'test' => ['test.qts.com'],
    'dev' => ['iz2ze6l1byo7n5f7wzqwtzz'],
    'production' => [''],
    'local' => ['lnmp_php'],
];
if (!$app->runningInConsole()) { //HTTP形式
    if (empty($_SERVER['HTTP_HOST'])) {
        die('[error] no host');
    }
    foreach ($env_hosts as $env => $host) {
        if (in_array(gethostname(), $host)) {
            $app_env = $env;
            break;
        }
    }
} else {//其它形式
    $app_env = $app->detectEnvironment(function () {
        return 'production';
    });
}
if (empty($app_env) || empty($env_hosts[$app_env])) {
    die('[error] no environment');
}

//写入环境配置
$loader = new \Dotenv\Loader('');
$loader->setEnvironmentVariable('APP_ENV', gethostname());
//载入配置文件,已经配置文件目录
$app->loadEnvironmentFrom(env('APP_ENV') . '.env')
    ->useEnvironmentPath(base_path(''));